/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.unesp.ia.gridsolver.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Pardal
 */
@Entity
@Table(name = "materia", catalog = "cursos", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Materia.findAll", query = "SELECT m FROM Materia m"),
    @NamedQuery(name = "Materia.findByIdMateria", query = "SELECT m FROM Materia m WHERE m.idMateria = :idMateria"),
    @NamedQuery(name = "Materia.findBySemestreIdeal", query = "SELECT m FROM Materia m WHERE m.semestreIdeal = :semestreIdeal"),
    @NamedQuery(name = "Materia.findByNome", query = "SELECT m FROM Materia m WHERE m.nome = :nome"),
    @NamedQuery(name = "Materia.findByCodigo", query = "SELECT m FROM Materia m WHERE m.codigo = :codigo")})
public class Materia implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idMateria", nullable = false)
    private Integer idMateria;
    @Column(name = "SemestreIdeal")
    private Integer semestreIdeal;
    @Size(max = 256)
    @Column(name = "Nome", length = 256)
    private String nome;
    @Size(max = 15)
    @Column(name = "Codigo", length = 15)
    private String codigo;
    @JoinTable(name = "prerequisito", joinColumns = {
        @JoinColumn(name = "Materia", referencedColumnName = "idMateria", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "Pre", referencedColumnName = "idMateria", nullable = false)})
    @ManyToMany
    private List<Materia> materiaList;
    @ManyToMany(mappedBy = "materiaList")
    private List<Materia> materiaList1;
    @ManyToMany(mappedBy = "materiaList")
    private List<Aluno> alunoList;
    @JoinColumn(name = "Curso", referencedColumnName = "idCurso", nullable = false)
    @ManyToOne(optional = false)
    private Curso curso;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "materia1")
    private List<Slotmateria> slotmateriaList;

    public Materia() {
    }

    public Materia(Integer idMateria) {
        this.idMateria = idMateria;
    }

    public Integer getIdMateria() {
        return idMateria;
    }

    public void setIdMateria(Integer idMateria) {
        this.idMateria = idMateria;
    }

    public Integer getSemestreIdeal() {
        return semestreIdeal;
    }

    public void setSemestreIdeal(Integer semestreIdeal) {
        this.semestreIdeal = semestreIdeal;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getCodigo() {
        return codigo;
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    @XmlTransient
    public List<Materia> getMateriaList() {
        return materiaList;
    }

    public void setMateriaList(List<Materia> materiaList) {
        this.materiaList = materiaList;
    }

    @XmlTransient
    public List<Materia> getMateriaList1() {
        return materiaList1;
    }

    public void setMateriaList1(List<Materia> materiaList1) {
        this.materiaList1 = materiaList1;
    }

    @XmlTransient
    public List<Aluno> getAlunoList() {
        return alunoList;
    }

    public void setAlunoList(List<Aluno> alunoList) {
        this.alunoList = alunoList;
    }

    public Curso getCurso() {
        return curso;
    }

    public void setCurso(Curso curso) {
        this.curso = curso;
    }

    @XmlTransient
    public List<Slotmateria> getSlotmateriaList() {
        return slotmateriaList;
    }

    public void setSlotmateriaList(List<Slotmateria> slotmateriaList) {
        this.slotmateriaList = slotmateriaList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idMateria != null ? idMateria.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Materia)) {
            return false;
        }
        Materia other = (Materia) object;
        if ((this.idMateria == null && other.idMateria != null) || (this.idMateria != null && !this.idMateria.equals(other.idMateria))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.unesp.ia.gridsolver.entity.Materia[ idMateria=" + idMateria + " ]";
    }
    
}
